|
|
|
|
|
|
|
The LoadImage API function allows you to load a bitmap, cursor, or icon file into a picture of a specified size while reducing aliasing effects. LoadImage cannot load other types of graphic files. This function takes as parameters the name of the file to load and the desired dimensions of the result. |
|
|
|
|
|
|
|
|
If it succeeds, LoadImage creates a bitmap containing the file's image. The program can then use the SelectObject API function to select the bitmap into a picture box for display. The LoadImageFile subroutine, shown in the following code, uses this technique to load an image file into a picture box, resizing the image to fit. |
|
|
|
 |
|
|
|
|
' Load a picture into a PictureBox using LoadImage. Private Sub LoadImageFile(ByVal pic As PictureBox, _
ByVal file_name As String)
Dim wid As Long
Dim hgt As Long
Dim hbmp As Long
Dim image_hdc As Long
' Get the PictureBox's dimensions in pixels. wid = pic.ScaleX(pic.ScaleWidth, pic.ScaleMode, vbPixels)
hgt = pic.ScaleY(pic.ScaleHeight, pic.ScaleMode, vbPixels)
' Load the bitmap. hbmp = LoadImage(0, file_name, 0, _
wid, hgt, LR_LOADFROMFILE)
' Make the picture box display the image. SelectObject pic.hdc, hbmp
' Destroy the bitmap to free its resources. DeleteObject hbmp
' Refresh the image. pic.Refresh
End Sub |
|
|
|
|
|
|
|
|
Example program LoadImg, shown in Figure 6.1, demonstrates the LoadImage function. Enter the name of an image file and a scale factor, and click the Load button. The left image shows the file's original picture. The center image shows the picture resized with PaintPicture. The image on the right is loaded by the LoadImageFile subroutine. In Figure 6.1, you can see that LoadImage produced a much better result. |
|
|
|
|
|
|
|
|
Example program ThumbImg is very similar to program Thumbs described in Chapter 1, Visual Basics. Both programs display small thumbnail images of the files in a directory. The main difference between the programs is that ThumbImg uses the LoadImage API function to display thumbnails for bitmap files. It uses Visual Basic's PaintPicture function to display thumbnails for other types of files. |
|
|
|
|
|
|
|
|
Use the program's DriveList, DirectoryList, and FileList controls to search your computer's files. When you select a directory and press F5, the program examines the files |
|
|
|
|
|